<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>班级添加</title>
		<base href="<%=request.getContextPath()%>/">
		<link rel="stylesheet" type="text/css" href="css/addClass.css"/>
		<script type="text/javascript" src="js/public/jquery-2.1.1.min.js"></script>
	</head>
	<body>
		<table  cellpadding="0px" cellspacing="0px" width="400px" height="400px" class="tb">
			<tr height="10%">
				<td colspan="2" align="center" class="cladd">班级添加</td>
				
			</tr>
			<tr>
				<td align="center">班级名称</td>
				<td align="center"><input type="text" id="cname"/></td>
			</tr>
			<tr>
				<td align="center">带班老师</td>
				<td align="center">
				
				<select name="tname" id="teacher">
				
				</select>
				</td>
			</tr>
			<tr>
				<td align="center">开班时间</td>
				<td align="center"><input type="date" name="addtime" id="time"/></td>
			</tr>
			<tr>
				<td align="center"><input type="button"  id="add" value="添加" /></td>
				<td align="center"><input type="reset" value="取消" /></td>
			</tr>
			<tr height="10%">
				<td colspan="2" class="cladd" id="info"></td>
			
			</tr>
			
		</table>
	</body>
	<script type="text/javascript">
	$(function(){
		//查找所有的老师信息
		$.ajax({
			url:"teacher/findAll",
			type:"get",
			success:function(data){
				$.each(data,function(index,val){
					var select =$("#teacher");
					var option=$("<option></option>");
					option.val(val.id);
					option.text(val.tname);
					select.append(option);
				});
			}
			
		});
		$("#add").click(function(){
			var cname=$("#cname").val();
			var tid=$("#teacher").val();
			var time=$("#time").val();
			if(cname==""){
				alert("班级名称必须填写");
				return;
			}
			if(tid==""){
				alert("带班老师必须填写");
				return;
			}
			if(time==""){
				alert("开班时间必须填写");
				return;
			}
		
			$.ajax({
				url:"cla/add",
				type:"post",
				dataType:"json",
				data:{'cname':cname,'tid':tid,'time':time},
				success:function(data){
					if(data>0){
						$("#info").html("<font color=green>添加成功</font>")
					}else{
						$("#info").html("<font color=red>添加失败</font>")	
					}
				}
			});
		});
	})
	</script>
</html>
